package com.ruoyi.project.data.service.impl;

import java.util.List;
import java.util.Map;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.project.data.domain.TbTransportDriverRequirements;
import com.ruoyi.project.data.mapper.TbTransportDriverRequirementsMapper;
import com.ruoyi.project.data.service.ITbTransportDriverRequirementsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 人员从业资格Service业务层处理
 *
 * @author ruoyi
 * @date 2020-03-23
 */
@Service
public class TbTransportDriverRequirementsServiceImpl implements ITbTransportDriverRequirementsService
{
    @Autowired
    private TbTransportDriverRequirementsMapper tbTransportDriverRequirementsMapper;

    /**
     * 查询人员从业资格
     *
     * @param requirementId 人员从业资格ID
     * @return 人员从业资格
     */
    @Override
    public TbTransportDriverRequirements selectTbTransportDriverRequirementsById(Long requirementId)
    {
        TbTransportDriverRequirements driverRequirements = tbTransportDriverRequirementsMapper.selectTbTransportDriverRequirementsById(requirementId);
        if("0".equals(driverRequirements.getIsValid())){
            // 根据身份证号获取人员识别驾驶证号
            Map<String, Object> driverMap = tbTransportDriverRequirementsMapper.selectDriverDistinguish(driverRequirements.getUserIdCard());
            if(driverMap != null){
                driverRequirements.setSbjszh(driverMap.get("num")==null?"":driverMap.get("num").toString());
            }
        }
        return driverRequirements;
    }

    /**
     * 查询人员从业资格列表
     *
     * @param tbTransportDriverRequirements 人员从业资格
     * @return 人员从业资格
     */
    @Override
    public List<TbTransportDriverRequirements> selectTbTransportDriverRequirementsList(TbTransportDriverRequirements tbTransportDriverRequirements)
    {
        return tbTransportDriverRequirementsMapper.selectTbTransportDriverRequirementsList(tbTransportDriverRequirements);
    }

    /**
     * 新增人员从业资格
     *
     * @param tbTransportDriverRequirements 人员从业资格
     * @return 结果
     */
    @Override
    public int insertTbTransportDriverRequirements(TbTransportDriverRequirements tbTransportDriverRequirements)
    {
        tbTransportDriverRequirements.setCreateTime(DateUtils.getNowDate());
        return tbTransportDriverRequirementsMapper.insertTbTransportDriverRequirements(tbTransportDriverRequirements);
    }

    /**
     * 修改人员从业资格
     *
     * @param tbTransportDriverRequirements 人员从业资格
     * @return 结果
     */
    @Override
    public int updateTbTransportDriverRequirements(TbTransportDriverRequirements tbTransportDriverRequirements)
    {
        tbTransportDriverRequirements.setUpdateTime(DateUtils.getNowDate());
        tbTransportDriverRequirements.setAuthenticationtype("1");
        return tbTransportDriverRequirementsMapper.updateTbTransportDriverRequirements(tbTransportDriverRequirements);
    }

    /**
     * 批量删除人员从业资格
     *
     * @param requirementIds 需要删除的人员从业资格ID
     * @return 结果
     */
    @Override
    public int deleteTbTransportDriverRequirementsByIds(Long[] requirementIds)
    {
        return tbTransportDriverRequirementsMapper.deleteTbTransportDriverRequirementsByIds(requirementIds);
    }

    /**
     * 删除人员从业资格信息
     *
     * @param requirementId 人员从业资格ID
     * @return 结果
     */
    @Override
    public int deleteTbTransportDriverRequirementsById(Long requirementId)
    {
        return tbTransportDriverRequirementsMapper.deleteTbTransportDriverRequirementsById(requirementId);
    }

    @Override
    public List<TbTransportDriverRequirements> selectDriverList(TbTransportDriverRequirements tbTransportDriverRequirements) {
        return tbTransportDriverRequirementsMapper.selectDriverList(tbTransportDriverRequirements);
    }
}
